<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta charset="UTF-8" />
<title>广告位管理</title>
<link rel="stylesheet" type="text/css" href="../Public/jquery-easyui-1.3.4/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="../Public/jquery-easyui-1.3.4/themes/icon.css">
<script type="text/javascript" src="../Public/jquery-easyui-1.3.4/jquery.min.js"></script>
<script type="text/javascript" src="../Public/jquery-easyui-1.3.4/jquery.easyui.min.js"></script>
<script type="text/javascript">
$.fn.datebox.defaults.formatter = function(date){
var y = date.getFullYear();
var m = date.getMonth()+1;
var d = date.getDate();
return y+'-'+(m<10?'0'+m:m)+'-'+(d<10?'0'+d:d);
};
$(document).ready(function(){
	$('#mytable').datagrid({
		nowrap: false,
		striped: true,
		url:'<{:U("indexjson")}>',
		loadMsg:'数据正在加载，请稍候...',
		columns:[[
			{field:'table_id',checkbox:true},
			{field:'table_name',title:'广告位名称',width:150,align:"left"},
			{field:'table_channel',title:'所属频道',width:120,align:"left",formatter:function(value){
				return value.channelname;
			}},
			{field:'table_type',title:'广告位类型',width:120,align:"left",formatter:function(value){
				return value.typename;
			}},
			{field:'table_width',title:'宽',width:60,align:"center",formatter:function(value){
				var value = value ? value+'px' : '0px';
				return value;
			}},
			{field:'table_height',title:'高',width:60,align:"center",formatter:function(value){
				var value = value ? value+'px' : '0px';
				return value;
			}},
			
			{field:'table_status',title:'状态',width:50,align:"left",formatter:function(value){
				if(value=='1'){
					return '<font color=red>删除</font>';
				}else if(value=='2'){
					return '<font color=#FFCC00>禁用</font>';
				}else{
					return '正常';
				}
			}}
		]],
		singleSelect:true,
		fit:true,
		pagination:true,
		pageSize:20,
		toolbar:[{
			text:'新增广告位',
			iconCls:'icon-add',
			handler:addAction
		},'-',{
			text:'编辑广告位',
			iconCls:'icon-edit',
			handler:editAction
		},'-',{
			text:'禁用广告位',
			iconCls:'icon-edit',
			handler:disableAction
		},'-',{
			text:'取消禁用广告位',
			iconCls:'icon-edit',
			handler:enableAction
		},'-',{
			text:'删除广告位',
			iconCls:'icon-remove',
			handler:removeAction
		}]
	});
	
	
	$('#form_channelid').combotree({
		width:235,
		treeWidth:250,
		treeHeight:400,
		required:true,
		missingMessage:'必选，不能选择存在子级频道的父频道',
		url:'<{:U("Channel/treejson")}>',
	});

});

function addAction(){
	$("#form_name").val('');
	$('#form_channelid').combotree('setValue', 0);
	$("#form_typeid").val('0');
	$("#form_width").val('');
	$("#form_height").val(''); 
	$("#formWindow").window('setTitle','新增广告位');
	$("#submit").unbind("click");
	$("#submit").bind("click",{action:"<{:U('add')}>"},checkSubmit);
	$("#formWindow").window('open');
	$("#myLayout").layout('resize');
}
function editAction(){
	var selected = $('#mytable').datagrid('getSelected');
	if(!selected){
		$.messager.alert('错误消息','请先选择一个广告位再编辑！','error');
	}else{
		$("#form_name").val(selected.table_name);
		
		$('#form_channelid').combotree('setValue',selected.table_channel.channelid);
		$("#form_typeid").val(selected.table_type.typeid);
		$("#form_width").val(selected.table_width);
		$("#form_height").val(selected.table_height);
		$("#formWindow").window('setTitle','编辑广告位');
		$("#submit").unbind("click");
		$("#submit").bind("click",{action:"<{:U('edit')}>",form_id:selected.table_id},checkSubmit);
		$("#formWindow").window('open');
		$("#myLayout").layout('resize');
	}
}
function removeAction(){
	var selected = $('#mytable').datagrid('getSelected');
	if(!selected){
		$.messager.alert('错误消息','请先选择一个广告位再删除！','error');
	}else{
		$.messager.confirm('提示消息','确认删除？',function(r){
			if(r){
				$.post('<{:U("remove")}>','form_id='+selected.table_id,function(data){
					if(data.status=='false'){
						$.messager.alert('错误消息',data.info,'error');
					}else{
						$.messager.alert('提示消息',data.info,'info',function(){
							$("#mytable").datagrid('reload');
						});
					}
				},"json");
			}
		});
	}
}
function disableAction(){
	var selected = $('#mytable').datagrid('getSelected');
	if(!selected){
		$.messager.alert('错误消息','请先选择一个广告位再禁用！','error');
	}else{
		$.messager.confirm('提示消息','确认禁用？',function(r){
			if(r){
				$.post(window.location.href,'submit=disable&form_id='+selected.table_id,function(data){
					if(data.status=='false'){
						$.messager.alert('错误消息',data.msg,'error');
					}else{
						$.messager.alert('提示消息',data.msg,'info',function(){
							$("#mytable").datagrid('reload');
						});
					}
				},"json");
			}
		});
	}
}
function enableAction(){
	var selected = $('#mytable').datagrid('getSelected');
	if(!selected){
		$.messager.alert('错误消息','请先选择一个广告位再取消禁用！','error');
	}else{
		$.messager.confirm('提示消息','确认取消禁用？',function(r){
			if(r){
				$.post(window.location.href,'submit=enable&form_id='+selected.table_id,function(data){
					if(data.status=='false'){
						$.messager.alert('错误消息',data.msg,'error');
					}else{
						$.messager.alert('提示消息',data.msg,'info',function(){
							$("#mytable").datagrid('reload');
						});
					}
				},"json");
			}
		});
	}
}
function closeForm(){
	$("#formWindow").window('close');
}
function checkSubmit(event){
	if(!$("#myForm").form('validate')){
		$.messager.alert('错误消息','请确保表单信息无误再提交！','error');
	}else{
		if($("#form_typeid").val()=='0'){
			$.messager.alert('错误消息','请选择广告位类型！','error');
			return;
		}

		closeForm();
		$.post(event.data.action,$('#myForm').serialize()+'&form_id='+event.data.form_id,function(data){
			if(data.status=='false'){
				$.messager.alert('错误消息',data.info,'error');
			}else{
				$.messager.alert('提示消息',data.info,'info',function(){
					$("#mytable").datagrid('reload');
				});
			}
		},"json");
	
	}
}
function searchres(){
	var searchname = encodeURIComponent($.trim($("#searchname").val()));
	var searchchannelid = $('#searchchannelid').combotree('getValue');
	var searchtypeid = $("#searchtypeid").val();	
	$('#mytable').datagrid({pageNumber:'1',pageSize:'20',url:'ajax.php?act=adplace&searchname='+searchname+'&searchchannelid='+searchchannelid+'&searchtypeid='+searchtypeid});
}
function undo(){
	$("#searchname").val('');
	$('#searchchannelid').combotree('setValue',{
		id:0,
		text:'顶级频道'
	});
	$("#searchtypeid").val('0');
}
</script>
</head>
<body class="easyui-layout">
<div region="center" title="广告设置-&gt;广告位管理">
<div class="easyui-layout" fit="true">
	<div region="north" border="false" style="height:40px;padding:2px;padding-left:5px;background-color:#DFE8F6;font-size:11px;color:#15428B;"><table><tr><td>广告位名称：</td><td><INPUT TYPE="text" NAME="searchname" id="searchname" style="width:150px;"></td><td>所属频道：</td><td><SELECT NAME="searchchannelid" id="searchchannelid"></SELECT></td><td>广告位类型：</td><td><SELECT NAME="searchtypeid" id="searchtypeid" style="width:100px"><option value="0">──请选择──</option></SELECT></td><td><a class="easyui-linkbutton" icon="icon-search" onclick="searchres();">搜索</a>&nbsp;<a class="easyui-linkbutton" icon="icon-undo" onclick="undo();">重置</a></td></tr></table></div>
	<div region="center" border="true"><table id="mytable"></table></div>
</div>
</div>
<div id="formWindow" class="easyui-window" title="新增广告位" minimizable="false" collapsible="false" maximizable="false" closed="true" modal="true" style="width:500px;height:350px;padding:0px;">
	<div class="easyui-layout" fit="true" id="myLayout">
		<div region="center" border="false">
		<form id="myForm" method="post" style="width:450px;height:260px;">
			<div class="easyui-tabs" fit="true" plain="true" border="false">
				<div title="基本信息" style="padding:15px;">
				<table>
					<tr><td>广告位名称：</td><td><INPUT class="easyui-validatebox" required="true" missingMessage="广告位名称不能为空" TYPE="text" NAME="form_name" id="form_name" style="width:250px"></td></tr>
					<tr><td>所属频道：</td><td><SELECT NAME="form_channelid" id="form_channelid"></SELECT></td></tr>
					<tr><td>广告位类型：</td><td><SELECT NAME="form_typeid" id="form_typeid" style="width:250px"><option value="0">───请选择广告位类型───</option><{:$adplacetypeHTML}></SELECT></td></tr>
					<tr><td>宽：</td><td><INPUT TYPE="text"   NAME="form_width" class="easyui-numberbox" required="true" max="5000"  id="form_width" style="width:50px">&nbsp;px</td></tr>
					<tr><td>高：</td><td><INPUT TYPE="text"      NAME="form_height" class="easyui-numberbox" required="true" max="5000"  id="form_height" style="width:50px">&nbsp;px</td></tr>
				</table>
				</div>
			</div>
		</form>
		</div>
		<div region="south" border="false" style="text-align:right;height:30px;line-height:30px;">
			<a class="easyui-linkbutton" icon="icon-ok" href="javascript:void(0)" id="submit">确定</a>
			<a class="easyui-linkbutton" icon="icon-cancel" href="javascript:void(0)" onclick="closeForm()">取消</a>
		</div>
	</div>
</div>
</body>
</html>